﻿using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YiMeiJiaLibModel.Business;
using YiMeiJiaLibModel.Business.Dto;
using YiMeiJiaLibModel.Enums;
using YiMeiJiaService.Assembly;
using YiMeiJiaService.IService;

namespace YiMeiJiaApp.Pages.Home.Mall
{
     
    public partial class Detail
    {
        #region 服务组件

        [Inject] private IAcccount _account { get; set; }
        [Inject] private IGoods _goods { get; set; }

        [Inject] protected NavigationManager Navigation { get; set; }
       

        [Inject] protected IJSRuntime JSRuntime { get; set; }
        #endregion



        #region 绑定数据
      
        public int goods { get; set;  }
        public CoreCmsGoodsDto good;

        /// <summary>
        /// 商品的sku列表
        /// </summary>
        public List<CoreCmsProducts> linkSuk { get; set; }
        /// <summary>
        /// 商品选中的sku
        /// </summary>
        public CoreCmsProducts selectSku { get; set;  }
        #endregion
        /// <summary>
        /// 加载事件
        /// </summary>
        /// <returns></returns>
        protected override async Task OnInitializedAsync()
        {

            try
            {
                //获取传递进来的ID 参数
               
                 var  x = Common.GetParams( new Uri(Navigation.Uri).Query, "goods");
                if (!string.IsNullOrEmpty(x)){
                    goods = Convert.ToInt32(x);
                    good = await _goods.GetGoodDetail(goods);
                    linkSuk = good.sku;
                    selectSku = good.product;
                    

                }
                else
                {
                    await EvalJs.ExJs().Toast(JSRuntime, "无效数据", EmToast.cancel);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            await base.OnInitializedAsync();
        }

        /// <summary>
        /// 选择对应的SKU 
        /// </summary>
        /// <param name="skuid"></param>
        /// <returns></returns>
        public Task SelectSku(int skuid)
        {

            return Task.CompletedTask;
        }

        /// <summary>
        /// 购买
        /// </summary>
        /// <param name="skuid"></param>
        /// <returns></returns>
        public async Task Buys(int skuid)
        {
            await EvalJs.ExJs().Toast(JSRuntime, "测试按钮", EmToast.succee);
            //return Task.CompletedTask;
        }

        public async Task Buys2(int skuid)
        {
            await EvalJs.ExJs().Toast(JSRuntime, "测试按钮2", EmToast.succee);
            //return Task.CompletedTask;
        }


    }
}
